package at.fhooe.im440.pandora.io;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import at.fhooe.im440.core.Core;
import at.fhooe.im440.pandora.events.KeyPressedEvent;

public class KeyboardManager implements KeyListener {

	private boolean[] keysPressed;
	private Core core;
	public boolean getKeyPressed(int i) {
		return keysPressed[i];
	}

	public KeyboardManager(Core core){
		this.core = core;
		keysPressed = new boolean[256];
	}
	
	public void keyPressed(KeyEvent e) {

		if (e.getKeyCode() >= 0 && e.getKeyCode() < 256) {
			keysPressed[e.getKeyCode()] = true;
			core.eventMgr.addEvent(new KeyPressedEvent(e.getKeyCode()));
		}
		e.consume();
	}

	public void keyReleased(KeyEvent e) {
		if (e.getKeyCode() >= 0 && e.getKeyCode() < 256) {
			keysPressed[e.getKeyCode()] = false;
		}
		e.consume();
	}

	public void keyTyped(KeyEvent e) {
		e.consume();
	}

}
